package com.job51.hro.datacheckservice.service.jobhandlers;

import com.alibaba.fastjson.JSONObject;
import com.job51.hro.datacheckservice.dto.xxjob.CustomErrorMail;
import com.job51.hro.datacheckservice.service.ErrorMailService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author pengfei.ma
 * @create 2022/6/15
 * @since 1.0.0
 */
@Service
@Slf4j
public class Logs {

    @Autowired
    ErrorMailService errorMailService;

    @XxlJob("sendErrorLogMail")
    public ReturnT<String> sendErrorLogMail(String param) throws Exception {
        CustomErrorMail customErrorMail = new CustomErrorMail();
        if (param.length() > 0) {
            customErrorMail = JSONObject.parseObject(param, CustomErrorMail.class);
        }
        if (errorMailService.sendLogMail(customErrorMail)) {
            return ReturnT.SUCCESS;
        } else {
            return ReturnT.FAIL;
        }
    }
}
